
#include "Scene/HelpScene.h"
#include "Scene/MainMenuScene.h"
#include "ui/CocosGUI.h"
#include <iostream>

USING_NS_CC;
using namespace ui;

Scene* HelpScene::createScene() {
    return HelpScene::create(); // Create a help scene
}

bool HelpScene::init() {
    if (!Scene::init()) {
        return false;
    }
    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    //// Background image
    auto help_background_sprite1 = Sprite::create("Games/GameLeft.png");
    help_background_sprite1->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
    help_background_sprite1->setScale(1.8f);
    this->addChild(help_background_sprite1, 0); // Add the background in layer 0

     //// Background image1
    auto help_background_sprite2 = Sprite::create("Games/letter_bg.png");
    help_background_sprite2->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2 + visibleSize.height * 0.13));
    help_background_sprite2->setScale(2.2f);
    this->addChild(help_background_sprite2, 1); // Add the background in layer 1

    //// Add label "help", ui::Label implementation
    //// Appeal to Typeface for fonts.
    //auto label_help = Label::createWithTTF("Help", "TypeFace/STXINWEI.ttf", 36);
    //label_help->enableShadow(); // Add shadow effect
    //label_help->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2 + visibleSize.height * 0.3));
    //label_help->setColor(Color3B::RED);
    //this->addChild(label_help, 2); // Add this label in layer 2

    // Add label rules
    auto label_rule1 = Label::createWithTTF("Help for Game", "TypeFace/STXINWEI.ttf", 35);
    label_rule1->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 1.15 - visibleSize.height * 0.07));
    label_rule1->setColor(Color3B::BLACK);
    this->addChild(label_rule1, 2);

    auto label_rule2 = Label::createWithTTF("When the Zombies show up,", "TypeFace/Marker Felt.ttf", 35);
    label_rule2->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 1.15 - visibleSize.height * 0.18));
    label_rule2->setColor(Color3B::BLACK);
    this->addChild(label_rule2, 2);

    auto label_rule3 = Label::createWithTTF("don't do anything. Then you", "TypeFace/Marker Felt.ttf", 35);
    label_rule3->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 1.15 - visibleSize.height * 0.28));
    label_rule3->setColor(Color3B::BLACK);
    this->addChild(label_rule3, 2);

    auto label_rule4 = Label::createWithTTF("will win the game!", "TypeFace/Marker Felt.ttf", 35);
    label_rule4->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 1.15 - visibleSize.height * 0.38));
    label_rule4->setColor(Color3B::BLACK);
    this->addChild(label_rule4, 2);

    /*auto label_rule5 = Label::createWithTTF("to your house.", "TypeFace/Marker Felt.ttf", 35);
    label_rule5->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 1.15 - visibleSize.height * 0.38));
    label_rule5->setColor(Color3B::BLACK);
    this->addChild(label_rule5, 2);*/

    auto label_rule6 = Label::createWithTTF("                                                              - the Zombies", "TypeFace/Marker Felt.ttf", 15);
    label_rule6->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 1.15 - visibleSize.height * 0.44));
    label_rule6->setColor(Color3B::BLACK);
    this->addChild(label_rule6, 2);

    // Add label developer
    auto label_developer = Label::createWithTTF("Developers: Cpt11, I Believe, kazimiyuuka66, WYP, Shiki, Qiu Zeping, 404", "TypeFace/Marker Felt.ttf", 25);
    label_developer->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 1.15 - visibleSize.height * 0.68));
    label_developer->setColor(Color3B::YELLOW);
    this->addChild(label_developer, 2);


    // Add the button "return", implementing by ui::button 
    // Switch to MainMenuScene
    auto button_return = Button::create("Games/selectSure0.png", "Games/selectSure1.png", "Games/selectSure0.png");
    button_return->setTouchEnabled(true);
    //button_return->setScale(0.1f);
    //button_return->setTitleText("Return"); // button label
    button_return->addTouchEventListener([&](Ref* sender, Widget::TouchEventType type) {
        switch (type)
        {
        case ui::Widget::TouchEventType::BEGAN:
            Director::getInstance()->replaceScene(MainMenuScene::create()); // Background switch, to MainMenuScene
            break;
        case ui::Widget::TouchEventType::ENDED:
            //std::cout << "Button clicked" << std::endl;
            log("Button clicked");
            break;
        default:
            break;
        }
        });
    button_return->setPosition(Vec2(origin.x+visibleSize.width / 2, origin.y + visibleSize.height * 0.18 + 30));
    button_return->setScale(3);
    this->addChild(button_return, 2);

//#endif // Debug
    // To be continue...


    return true;
}


void HelpScene::menuCloseCallback(Ref* pSender) {
    //Close the cocos2d-x game scene and quit the application
    Director::getInstance()->end();
}



